package cn.hs.blog.user.action;

import java.io.IOException;
import java.util.List;

import javax.jdo.PersistenceManager;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.hs.blog.base.PMF;
import cn.hs.blog.user.module.User;

public class UserAction {

    public void list(HttpServletRequest req, HttpServletResponse resp)
        throws IOException {
        System.out.println("UserListAction");
        PersistenceManager pm = PMF.get().getPersistenceManager();
        String query = "select from " + User.class.getName() + " order by id ";

        System.out.println("JDOQL: " + query);
        List<User> users = (List<User>) pm.newQuery(query).execute();

        req.setAttribute("list", users);
        try {
            req.getRequestDispatcher("/jsp/admin/userList.jsp").forward(req, resp);
        } catch (ServletException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

    }

}
